package com.company.beauty.common.config;

import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>配置hibernate Validator为快速失败返回模式</p>
 *
 * @author youyoukele
 * @version 1.0
 * @date 2023/11/27
 */
@Slf4j
@Configuration
public class ValidatorConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public Validator validator() {
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                .configure().addProperty("hibernate.validator.fail_fast", "true")
                .buildValidatorFactory();
        log.info("common handler validator!!!!");
        return validatorFactory.getValidator();
    }

}
